// Copyright (c) 2023 CHANGLEI. All rights reserved.

import 'package:flutter/cupertino.dart';
import 'package:flutter_grasp/src/widget/grown_flex.dart';

/// Created by changlei on 2020-02-13.
///
/// `GrownRow` is a widget that extends `GrownFlex` and sets the direction to horizontal.
/// It's a wrapper around the `Row` widget, providing a unified way to handle margins and dividers.
class GrownRow extends GrownFlex {
  /// Creates a `GrownRow` widget.
  ///
  /// The [children] argument must not be null. If [divider] is not null, it will be inserted between each pair of children.
  /// The [crossAxisAlignment] and [textBaseline] arguments must not be null if the [crossAxisAlignment] is set to [CrossAxisAlignment.baseline].
  GrownRow({
    super.key,
    super.mainAxisAlignment,
    super.crossAxisAlignment,
    super.mainAxisSize,
    super.textDirection,
    super.verticalDirection,
    super.textBaseline,
    super.clipBehavior,
    required super.children,
    super.divider,
  }) : super(
          direction: Axis.horizontal,
        );

  /// Creates a `GrownRow` widget with space between each child.
  ///
  /// The [spacing] argument must be non-negative. If it's greater than 0, a `SizedBox` widget with the specified width will be inserted between each pair of children.
  @Deprecated(r'Use `Row` instead.')
  factory GrownRow.spacing({
    Key? key,
    MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
    CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
    MainAxisSize mainAxisSize = MainAxisSize.max,
    TextDirection? textDirection,
    VerticalDirection verticalDirection = VerticalDirection.down,
    TextBaseline? textBaseline,
    Clip clipBehavior = Clip.none,
    required List<Widget>? children,
    double? spacing = 0,
  }) {
    assert(spacing == null || spacing >= 0);
    Widget? divider;
    if (spacing != null && spacing > 0) {
      divider = SizedBox(
        width: spacing,
      );
    }
    return GrownRow(
      key: key,
      mainAxisAlignment: mainAxisAlignment,
      crossAxisAlignment: crossAxisAlignment,
      mainAxisSize: mainAxisSize,
      textDirection: textDirection,
      verticalDirection: verticalDirection,
      textBaseline: textBaseline,
      clipBehavior: clipBehavior,
      divider: divider,
      children: children,
    );
  }

  /// Creates a `GrownRow` widget with a builder function for creating each child.
  ///
  /// The [itemBuilder] argument must not be null. The [itemCount] argument must be non-negative.
  GrownRow.builder({
    super.key,
    super.mainAxisAlignment,
    super.crossAxisAlignment,
    super.mainAxisSize,
    required super.itemBuilder,
    required super.itemCount,
    super.textDirection,
    super.verticalDirection,
    super.textBaseline,
    super.clipBehavior,
  }) : super.builder(
          direction: Axis.horizontal,
        );

  /// Creates a `GrownRow` widget with a builder function for creating each child and a separate builder function for creating separators.
  ///
  /// The [itemBuilder] and [separatorBuilder] arguments must not be null. The [itemCount] argument must be non-negative.
  GrownRow.separated({
    super.key,
    super.mainAxisAlignment,
    super.crossAxisAlignment,
    super.mainAxisSize,
    required super.itemBuilder,
    required super.separatorBuilder,
    required super.itemCount,
    super.textDirection,
    super.verticalDirection,
    super.textBaseline,
    super.clipBehavior,
  }) : super.separated(
          direction: Axis.horizontal,
        );

  /// Creates a `GrownRow` widget with a custom delegate for creating children.
  ///
  /// The [childrenDelegate] argument must not be null.
  const GrownRow.custom({
    super.key,
    super.mainAxisAlignment,
    super.crossAxisAlignment,
    super.mainAxisSize,
    required super.childrenDelegate,
    super.textDirection,
    super.verticalDirection,
    super.textBaseline,
    super.clipBehavior,
  }) : super.custom(
          direction: Axis.horizontal,
        );
}
